/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package personadultbaby;

import java.util.ArrayList;
import java.util.Iterator;

/**
 *
 * @author Ngocvan
 */
public class Adult extends Person{
    protected Wallet wallet = new Wallet();
    protected ArrayList listeners = new ArrayList();
    public Adult(String fname){
        this.firstName = fname;
    };
    
    @Override
    public String toString(){
        return this.firstName;
    }
    @Override
    public void move () {
//        System.out.println("Moved.");
        super.move();
        fireMoveEvent();
    }
    
    /**
     *
     */
    @Override
    public void talk () {
        System.out.println("Spoke.");
    }
    
    /**
     *
     * @param aBill
     */
    public void acceptMoney(int aBill){
        this.wallet.addBill(aBill);
    }
    
    public int moneyTotal(){
       return this.wallet.getMoneyTotal();
    }

    public void addMotionListener(IMotionListener aListener){
        this.listeners.add(aListener);
    }
    
    private void fireMoveEvent() {
        for (Iterator it = listeners.iterator(); it.hasNext();) {
            IMotionListener aListener;
            aListener = (IMotionListener) it.next();
            aListener.handleMove(this);
        }
    }
    
    protected class Wallet {
        protected ArrayList bills = new ArrayList();
        protected void addBill(int aBill){
            bills.add(new Integer(aBill));
        }
        protected int getMoneyTotal(){
            int total = 0;
            for ( Iterator i= bills.iterator(); i.hasNext(); ){
                Integer wrappedBill = (Integer) i.next();
                int bill = wrappedBill.intValue();
                total += bill;
            }
            return total;
        }
    }
}
